import React from 'react';
import { Toast, } from 'antd-mobile';

export default class Index extends React.Component {
    constructor(props){
        super(props)
        this.state={
			toMax: false,
			id: props.match.params.id,
			z_price: 0,
			is_free:1,
        }
    }
	componentDidMount(){
		document.title = '结算'
		global.Ajax.hhtc_request("product/pay_info",{id: this.state.id}).then(data=>{
			if(data.code===1){
                this.setState(data.data)
			}
		})
	}
	buy(){
		global.Ajax.hhtc_request("product/order",{id: this.state.id}).then(data=>{
			if(data.code===1){
                if(this.state.is_free===1){
					this.props.history.replace('/page/home/user/orderlist')
					return;
				}
				this.props.history.replace('/page/home/learn/pay/'+data.data+'/1')
			}else{
                Toast.fail(data.msg,1)
            }
		})
	}
	render(){
		return(
			<div className='check_order'>
                <div className='account'>
                    <p>购买账号</p>
                    <span>{this.state.phone}</span>
                </div>
				<div className='index_lj_list'>
					<div className='item'>
						<div className='picbox'>
							<img alt='' src={this.state.img} className='pic' />
							<p className='bq1'>视频</p>
						</div>
						<div className='right'>
							<p className='title'>{this.state.title}</p>
							<p className='desc'>{this.state.info}</p>
							<p className='peop'>{this.state.author}</p>
							<div className='flex'>
								{this.state.is_free===1&&<p className='pri'>免费</p>}
								{this.state.is_free===2&&<p className='pri'>￥{this.state.z_price*1}</p>}
								{this.state.is_free===3&&<div style={{'display':'flex'}}><p className='pri'>￥{this.state.z_price*1}</p><img alt='' src={require('../../imgs/hua.png')} style={{width: 14,height: 19,marginLeft: '5px'}} /></div>}
							</div>
						</div>
					</div>
				</div>
                <div className='bott'>
                    <p>需要支付：</p>
					{this.state.is_free===1&&<div><h1>免费</h1></div>}
					{this.state.is_free===2&&<h1>{this.state.z_price*1}元</h1>}
					{this.state.is_free===3&&<div><h1 style={{'display':'flex'}}>{this.state.z_price*1}<img alt='' src={require('../../imgs/hua.png')} style={{width: 14,height: 19}} /></h1></div>}
					{this.state.is_free===4&&<div><h1 style={{'display':'flex'}}>{this.state.z_price*1}<img alt='' src={require('../../imgs/999.png')} style={{width: 14,height: 19}} /></h1></div>}
                    <span onClick={this.buy.bind(this)}>提交订单</span>
                </div>
			</div>
		)
	}
}
